import { cartGet } from "../api/cake";
import { userLogin } from "../api/user"
import store from './index.js'
export default {
	namespaced:true,
	state:()=>({
		userInfo:null
	}),
	mutations:{
		initInfoMut(state,info){
			state.userInfo = info
		}
	},
	actions:{
		async userLoginAction(context,account){
			let res = await userLogin(account)
			console.log('登录成功',res);
			let {objectId} = res.data  //用户id
			let cart = await cartGet(objectId)
			console.log('线上购物车数据',cart);
			let {results} = cart.data
			let cartList = []
			if(results.length){
				cartList = results[0].cartList
				store.commit('cart/cartIdMut',results[0].objectId) //记录当前用户的购物车数据id
			}
			store.commit('cart/initCartListMut',cartList)
			context.commit('initInfoMut',res.data)
		}
	}
}